package com.rentong.wx.cust.controller;

import com.rentong.common.R;
import com.rentong.wx.cust.dao.CustMessageChatLogDao;
import com.rentong.wx.cust.domain.CustMessageChatLogEntity;
import com.rentong.wx.cust.service.CustMessageChatLogService;
import com.rentong.wx.utils.WxApiUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhangle
 * @email 459343178@qq.com
 * @date 2024-12-24 14:42:32
 */
@RestController
public class CustMessageChatLogController {

    @Autowired
    private CustMessageChatLogService custMessageChatLogService;


    /*
     * 7、查看聊天信息列表页面
     * */
    @GetMapping("/custMessageChatLog/getChatList")
    public R getChatList(HttpServletRequest request, Integer totalNum, Integer weidu) throws Exception {
        return R.success(custMessageChatLogService.getChatList(WxApiUtil.getCurrentCustId(request), totalNum, weidu));
    }

    /*
     * 8、查看聊天具体内容
     * */
    @GetMapping("/custMessageChatLog/getChatContent")
    public R getChatContent(HttpServletRequest request, Long userId) throws Exception {
//        return R.success(custMessageChatLogService.getChatContent(9L, 16L));
        return R.success(custMessageChatLogService.getChatContent(WxApiUtil.getCurrentCustId(request), userId));
    }

    /*
     *15、修改信息成未读状态
     * */
    @PutMapping("/custMessageChatLog/updateReadeStatus")
    public R updateReadeStatus(HttpServletRequest request, Long userId) throws Exception {
        Integer i = custMessageChatLogService.updateReadeStatus(WxApiUtil.getCurrentCustId(request), userId);
        if (i > 0) {
            return R.success("修改成功");
        } else {
            return R.error("修改失败");
        }
    }

    /*
     *16、删除信息列表中的信息
     * */
    @PostMapping("/custMessageChatLog/delInformation")
    public R delInformation(HttpServletRequest request, Long userId) throws Exception {
        Integer i = custMessageChatLogService.delInformation(WxApiUtil.getCurrentCustId(request), userId);

        if (i > 0) {
            return R.success("删除成功");
        } else {
            return R.error("删除失败");
        }
    }


    /*
     * 210、发送消息（图、文都是这个接口）
     * */
    @RequestMapping("/custMessageChatLog/insertMessageByCustId")
    public R insertMessageByCustId(CustMessageChatLogEntity custMessageChatLogEntity, HttpServletRequest request) throws Exception {
        custMessageChatLogEntity.setSenderId(WxApiUtil.getCurrentCustId(request));
        custMessageChatLogService.insertMessageByCustId(custMessageChatLogEntity);
        return R.success("操作成功！");
    }


}
